
package com.geelou.crossapp;

import org.CrossApp.lib.Cocos2dxActivity;
import org.CrossApp.lib.Cocos2dxGLSurfaceView;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import cn.sharesdk.ShareSDKUtils;

import com.geelou.crossapp.util.LogUtil;
import com.umeng.AnalyticsHome;
import com.umeng.message.PushAgent;
import com.umeng.update.UmengUpdateAgent;

public class BeautifulJelly extends Cocos2dxActivity{
	private Cocos2dxGLSurfaceView glSurfaceView;

    protected void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);	
		ShareSDKUtils.prepare();
		String s = getDeviceInfo(this);
		LogUtil.debug("设备信息："+s);
	}

    public Cocos2dxGLSurfaceView onCreateView() {
    	glSurfaceView = new Cocos2dxGLSurfaceView(this);
    	// GdLife should create stencil buffer
    	glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8);
    	AnalyticsHome.init(this);
    	LogUtil.debug("启动友盟自动更新");
    	UmengUpdateAgent.update(this);
    	
    	// 友盟消息推送
    	PushAgent mPushAgent = PushAgent.getInstance(this);
    	mPushAgent.enable();
    	
    	return glSurfaceView;
    }

    public boolean onKeyDown(final int pKeyCode, final KeyEvent pKeyEvent)
	{
		return glSurfaceView.onKeyDown(pKeyCode, pKeyEvent);
	}
    
    public boolean onKeyUp(final int pKeyCode, final KeyEvent pKeyEvent)
	{
		return glSurfaceView.onKeyUp(pKeyCode, pKeyEvent);
	}

    
    public static String getDeviceInfo(Context context) {
	    try{
	      org.json.JSONObject json = new org.json.JSONObject();
	      android.telephony.TelephonyManager tm = (android.telephony.TelephonyManager) context
	          .getSystemService(Context.TELEPHONY_SERVICE);
	
	      String device_id = tm.getDeviceId();
	
	      android.net.wifi.WifiManager wifi = (android.net.wifi.WifiManager) context.getSystemService(Context.WIFI_SERVICE);
	
	      String mac = wifi.getConnectionInfo().getMacAddress();
	      json.put("mac", mac);
	
	  if( TextUtils.isEmpty(device_id) ){
	      device_id = mac;
	  }
	
	  if( TextUtils.isEmpty(device_id) ){
	       device_id = android.provider.Settings.Secure.getString(context.getContentResolver(),android.provider.Settings.Secure.ANDROID_ID);
	  }
	
	  json.put("device_id", device_id);
	        return json.toString();
	  }catch(Exception e){
	         e.printStackTrace();
	  }
	  return null;
	} 
    
    public void onResume() {
        super.onResume();
        AnalyticsHome.onResume();       //统计时长
    }
    public void onPause() {
        super.onPause();
        AnalyticsHome.onPause();
    }
    
    static {
    	//System.loadLibrary("ffmpeg");
        System.loadLibrary("CrossApp_cpp");
    }    
}
